﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace shua_ru_seucrity_key
{
    public partial class security_key_generator : Form
    {
        private const string secu_secret = "LindeOS,.12";
        private string serial_number;
        private string mac_adress;
        private string security_key;
        public security_key_generator()
        {
            InitializeComponent();
        }

        private void buttonRun_Click(object sender, EventArgs e)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(serial_number.ToUpper() + secu_secret + mac_adress.ToUpper());
            byte[] hash = SHA256Managed.Create().ComputeHash(bytes);
            string local_key = "";
            for (int i = 0; i < 4; i++)
            {
                local_key += (hash[hash.Length - 4 + i].ToString("X2"));
            }
            textBoxKey.Text = local_key.ToUpper();
            
        }
        private void sn_TextChanged(object sender, EventArgs e)
        {
            serial_number = textBoxSN.Text.PadLeft(8, '0');
        }
        private void mac_addr_TextChanged(object sender, EventArgs e)
        {
            mac_adress = textBoxMac.Text.PadLeft(12, '0');
        }

        private void securityKey_TextChanged(object sender, EventArgs e)
        {
        }
    }
}
